import 'package:flutter/material.dart';

class AnimatedExample01Page extends StatefulWidget {
  const AnimatedExample01Page({super.key});

  @override
  State<AnimatedExample01Page> createState() => _AnimatedExample01PageState();
}

class _AnimatedExample01PageState extends State<AnimatedExample01Page> {
  bool flag = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Animated Example 01'),
      ),
      body: Center(
        child: Container(
          width: 300,
          height: 300,
          color: Colors.blue,
          child: AnimatedSwitcher(
            duration: const Duration(milliseconds: 1500),
            child: flag
                ? const CircularProgressIndicator(
                    strokeWidth: 10,
                  )
                : Image.network(
                    "https://fs.aihujiankang.com/f0a4172318f745d171896342af666af0d52b1bc2e2ebdcb74d41a74b4655476f.png",
                    fit: BoxFit.cover,
                  ),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            flag = !flag;
          });
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}
